import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:self32/page/borrow_page.dart';
import 'package:self32/page/mine_page.dart';
import 'package:self32/page/query_page.dart';
import 'package:self32/page/return_page.dart';

import '../main.dart';
import '../widget/focus_killer.dart';
import 'borrow_again_page.dart';
import 'setting_page.dart';

class QyIndex extends StatefulWidget {
  const QyIndex({Key? key}) : super(key: key);

  @override
  State<QyIndex> createState() => _QyIndexState();
}

class _QyIndexState extends State<QyIndex> {

  @override
  void dispose() {
    clock.cancel();
    super.dispose();
  }

  _action(){
    return Container(
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.all(Radius.circular(4.r)),
      ),
      padding: EdgeInsets.only(left: 8.r,right: 8.r,top: 8.r,bottom: 8.r),
      margin: EdgeInsets.only(left: 8.r,right: 8.r,top: 8.r,bottom: 8.r),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Column(
            children: [
              InkWell(
                onTap: (){
                  Get.to(()=> const Borrow());
                },
                child: Image.asset("assets/images/qy_borrow.png",width:182.w,fit: BoxFit.fitWidth,),
              ),
              SizedBox(height: 8.r,),
              InkWell(
                onTap: (){
                  Get.to(()=> const Return());
                },
                child: Image.asset("assets/images/qy_return.png",width:182.w,fit: BoxFit.fitWidth,),
              ),
            ],
          ),
          Column(
            children: [
              InkWell(
                onTap: (){
                  Get.to(()=> const Query());
                },
                child: Image.asset("assets/images/qy_query.png",width:182.w,fit: BoxFit.fitWidth,),
              ),
              SizedBox(height: 8.r,),
              InkWell(
                onTap: (){
                  Get.to(()=> const BorrowAgain());
                },
                child: Image.asset("assets/images/qy_borrow_again.png",width:182.w,fit: BoxFit.fitWidth,),
              ),
              SizedBox(height: 8.r,),
              InkWell(
                onTap: (){
                  Get.to(()=> const Mine());
                },
                child: Image.asset("assets/images/qy_mine.png",width:182.w,fit: BoxFit.fitWidth,),
              ),
            ],
          )
        ],
      ));
  }

  _version(){
    return Container(
      width: 46.w,
      height: 16.h,
      decoration: BoxDecoration(
        color: const Color.fromRGBO(219, 236, 255, 1),
        borderRadius: BorderRadius.all(Radius.circular(16.r)),
      ),
      child: Align(child: Text('V$version',style: TextStyle(color: Colors.black,fontSize: 8.sp)),)
    );
  }

  _appBar(){
    return Container(
        width: double.infinity,
        height: 40.h,
        padding: EdgeInsets.only(left: 8.r,right: 8.r),
        alignment: Alignment.center,
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            Text(settingEntity.deviceName??'轩毅',style: TextStyle(fontSize: 12.sp,color: Colors.black),),
            InkWell(
              onTap:(){
                Get.to(()=>const Setting());
              },
              child:  Obx(() => IntrinsicHeight(child: Row(
                children: [
                  Text(clock.time.value,style: TextStyle(fontSize: 14.sp,color: Colors.black),),
                  VerticalDivider(color: Colors.black,thickness: 1.w,indent:4,endIndent: 4,),
                  Text('${clock.day.value}\n${clock.weekDay.value}',style: TextStyle(fontSize: 6.sp,color: Colors.black),),
                ],
              ))),
            ),
          ],
        )
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Stack(
        alignment: AlignmentDirectional.center,
        children: [
          Container(
              width: double.infinity,
              height: double.infinity,
              decoration: const BoxDecoration(
                image: DecorationImage(
                  fit: BoxFit.fill,
                  image: AssetImage(
                    "assets/images/hfhbg.png",
                  ),
                ),
              ),
              child: Stack(
                children: [
                  Image.asset("assets/images/qy_top.png",),
                  _appBar(),
                  Align(child: focusKiller(),),
                  Positioned(top:250.h,left:0,right:0,child: _action()),
                  Positioned(top:150.h,left:18.w,child:  _version()),

                ],
              )
          ),

        ]
      )
    );
  }
}